{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>人员编号</th>\n",
       "      <th>部门名称</th>\n",
       "      <th>卡号</th>\n",
       "      <th>卡账号</th>\n",
       "      <th>类型名称</th>\n",
       "      <th>操作金额(元)</th>\n",
       "      <th>余额(元)</th>\n",
       "      <th>消费类型</th>\n",
       "      <th>餐厅</th>\n",
       "      <th>餐别</th>\n",
       "      <th>设备序列号</th>\n",
       "      <th>设备流水号</th>\n",
       "      <th>卡流水号</th>\n",
       "      <th>消费时间</th>\n",
       "      <th>上传时间</th>\n",
       "      <th>记录标志</th>\n",
       "      <th>操作员</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>G13868</td>\n",
       "      <td>基础构架部</td>\n",
       "      <td>1.673943e+09</td>\n",
       "      <td>34918.0</td>\n",
       "      <td>消费</td>\n",
       "      <td>0.01</td>\n",
       "      <td>546.74</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>东方宫餐厅</td>\n",
       "      <td>早餐</td>\n",
       "      <td>6.787154e+12</td>\n",
       "      <td>100003.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>2020-07-04 02:39:44</td>\n",
       "      <td>2020-07-07 11:18:05</td>\n",
       "      <td>设备上传</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>G13868</td>\n",
       "      <td>基础构架部</td>\n",
       "      <td>1.673943e+09</td>\n",
       "      <td>34918.0</td>\n",
       "      <td>消费</td>\n",
       "      <td>0.01</td>\n",
       "      <td>546.61</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>东方宫餐厅</td>\n",
       "      <td>早餐</td>\n",
       "      <td>6.787154e+12</td>\n",
       "      <td>100003.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>2020-07-04 02:56:27</td>\n",
       "      <td>2020-07-07 11:18:47</td>\n",
       "      <td>设备上传</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>G13567</td>\n",
       "      <td>NBT Capital</td>\n",
       "      <td>1.674528e+09</td>\n",
       "      <td>34451.0</td>\n",
       "      <td>消费</td>\n",
       "      <td>18.00</td>\n",
       "      <td>1373.70</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>东方宫餐厅</td>\n",
       "      <td>中餐</td>\n",
       "      <td>6.787154e+12</td>\n",
       "      <td>100004.0</td>\n",
       "      <td>74.0</td>\n",
       "      <td>2020-07-06 11:49:32</td>\n",
       "      <td>2020-07-07 11:18:05</td>\n",
       "      <td>设备上传</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>G9096</td>\n",
       "      <td>内容业务研发部</td>\n",
       "      <td>1.956033e+09</td>\n",
       "      <td>19874.0</td>\n",
       "      <td>消费</td>\n",
       "      <td>18.00</td>\n",
       "      <td>723.22</td>\n",
       "      <td>定值模式</td>\n",
       "      <td>东方宫餐厅</td>\n",
       "      <td>中餐</td>\n",
       "      <td>6.787154e+12</td>\n",
       "      <td>41002.0</td>\n",
       "      <td>1155.0</td>\n",
       "      <td>2020-07-06 11:49:49</td>\n",
       "      <td>2020-07-07 16:41:31</td>\n",
       "      <td>设备上传</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>G11886</td>\n",
       "      <td>业务拓展研发部</td>\n",
       "      <td>1.727953e+09</td>\n",
       "      <td>30588.0</td>\n",
       "      <td>消费</td>\n",
       "      <td>20.00</td>\n",
       "      <td>1031.40</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>东方宫餐厅</td>\n",
       "      <td>中餐</td>\n",
       "      <td>6.787154e+12</td>\n",
       "      <td>100005.0</td>\n",
       "      <td>561.0</td>\n",
       "      <td>2020-07-06 11:50:05</td>\n",
       "      <td>2020-07-07 11:18:05</td>\n",
       "      <td>设备上传</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61285</th>\n",
       "      <td>G13346</td>\n",
       "      <td>社会责任与公共关系发展中心</td>\n",
       "      <td>3.191372e+09</td>\n",
       "      <td>161900008.0</td>\n",
       "      <td>消费</td>\n",
       "      <td>16.00</td>\n",
       "      <td>908.74</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>东方宫餐厅</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>6.787154e+12</td>\n",
       "      <td>143189.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>2021-06-29 19:24:03</td>\n",
       "      <td>2021-06-29 19:23:58</td>\n",
       "      <td>设备上传</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61286</th>\n",
       "      <td>G2885</td>\n",
       "      <td>营收研发部</td>\n",
       "      <td>3.518234e+08</td>\n",
       "      <td>158700039.0</td>\n",
       "      <td>消费</td>\n",
       "      <td>16.00</td>\n",
       "      <td>529.58</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>东方宫餐厅</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>6.787154e+12</td>\n",
       "      <td>143190.0</td>\n",
       "      <td>69.0</td>\n",
       "      <td>2021-06-29 19:28:52</td>\n",
       "      <td>2021-06-29 19:28:47</td>\n",
       "      <td>设备上传</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61287</th>\n",
       "      <td>G13113</td>\n",
       "      <td>Noizz项目组</td>\n",
       "      <td>3.510890e+08</td>\n",
       "      <td>159000037.0</td>\n",
       "      <td>消费</td>\n",
       "      <td>16.00</td>\n",
       "      <td>60.64</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>东方宫餐厅</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>6.787154e+12</td>\n",
       "      <td>143191.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>2021-06-29 19:32:46</td>\n",
       "      <td>2021-06-29 19:32:40</td>\n",
       "      <td>设备上传</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61288</th>\n",
       "      <td>G2543</td>\n",
       "      <td>电商项目组</td>\n",
       "      <td>3.206524e+09</td>\n",
       "      <td>158800037.0</td>\n",
       "      <td>消费</td>\n",
       "      <td>16.00</td>\n",
       "      <td>19.12</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>东方宫餐厅</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>6.787154e+12</td>\n",
       "      <td>143192.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>2021-06-29 19:41:00</td>\n",
       "      <td>2021-06-29 19:40:54</td>\n",
       "      <td>设备上传</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61289</th>\n",
       "      <td>汇总</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1155432.82</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>61290 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         人员编号           部门名称            卡号          卡账号 类型名称     操作金额(元)  \\\n",
       "0      G13868          基础构架部  1.673943e+09      34918.0   消费        0.01   \n",
       "1      G13868          基础构架部  1.673943e+09      34918.0   消费        0.01   \n",
       "2      G13567    NBT Capital  1.674528e+09      34451.0   消费       18.00   \n",
       "3       G9096        内容业务研发部  1.956033e+09      19874.0   消费       18.00   \n",
       "4      G11886        业务拓展研发部  1.727953e+09      30588.0   消费       20.00   \n",
       "...       ...            ...           ...          ...  ...         ...   \n",
       "61285  G13346  社会责任与公共关系发展中心  3.191372e+09  161900008.0   消费       16.00   \n",
       "61286   G2885          营收研发部  3.518234e+08  158700039.0   消费       16.00   \n",
       "61287  G13113       Noizz项目组  3.510890e+08  159000037.0   消费       16.00   \n",
       "61288   G2543          电商项目组  3.206524e+09  158800037.0   消费       16.00   \n",
       "61289      汇总            NaN           NaN          NaN  NaN  1155432.82   \n",
       "\n",
       "         余额(元)  消费类型     餐厅   餐别         设备序列号     设备流水号    卡流水号  \\\n",
       "0       546.74  金额模式  东方宫餐厅   早餐  6.787154e+12  100003.0    72.0   \n",
       "1       546.61  金额模式  东方宫餐厅   早餐  6.787154e+12  100003.0    85.0   \n",
       "2      1373.70  金额模式  东方宫餐厅   中餐  6.787154e+12  100004.0    74.0   \n",
       "3       723.22  定值模式  东方宫餐厅   中餐  6.787154e+12   41002.0  1155.0   \n",
       "4      1031.40  金额模式  东方宫餐厅   中餐  6.787154e+12  100005.0   561.0   \n",
       "...        ...   ...    ...  ...           ...       ...     ...   \n",
       "61285   908.74  金额模式  东方宫餐厅   晚餐  6.787154e+12  143189.0    34.0   \n",
       "61286   529.58  金额模式  东方宫餐厅   晚餐  6.787154e+12  143190.0    69.0   \n",
       "61287    60.64  金额模式  东方宫餐厅   晚餐  6.787154e+12  143191.0    82.0   \n",
       "61288    19.12  金额模式  东方宫餐厅   晚餐  6.787154e+12  143192.0    56.0   \n",
       "61289      NaN   NaN    NaN  NaN           NaN       NaN     NaN   \n",
       "\n",
       "                      消费时间                 上传时间  记录标志  操作员  \n",
       "0      2020-07-04 02:39:44  2020-07-07 11:18:05  设备上传  0.0  \n",
       "1      2020-07-04 02:56:27  2020-07-07 11:18:47  设备上传  0.0  \n",
       "2      2020-07-06 11:49:32  2020-07-07 11:18:05  设备上传  0.0  \n",
       "3      2020-07-06 11:49:49  2020-07-07 16:41:31  设备上传  0.0  \n",
       "4      2020-07-06 11:50:05  2020-07-07 11:18:05  设备上传  0.0  \n",
       "...                    ...                  ...   ...  ...  \n",
       "61285  2021-06-29 19:24:03  2021-06-29 19:23:58  设备上传  0.0  \n",
       "61286  2021-06-29 19:28:52  2021-06-29 19:28:47  设备上传  0.0  \n",
       "61287  2021-06-29 19:32:46  2021-06-29 19:32:40  设备上传  0.0  \n",
       "61288  2021-06-29 19:41:00  2021-06-29 19:40:54  设备上传  0.0  \n",
       "61289                  NaN                  NaN   NaN  NaN  \n",
       "\n",
       "[61290 rows x 17 columns]"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取数据，为保证隐私，已经在Excel删除了员工姓名列\n",
    "path = '/Users/emmalui/Downloads/牛肉面一年的刷卡数据.xlsx'\n",
    "df_dong = pd.read_excel(path)\n",
    "df_dong"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 61290 entries, 0 to 61289\n",
      "Data columns (total 17 columns):\n",
      " #   Column   Non-Null Count  Dtype  \n",
      "---  ------   --------------  -----  \n",
      " 0   人员编号     61290 non-null  object \n",
      " 1   部门名称     61289 non-null  object \n",
      " 2   卡号       61289 non-null  float64\n",
      " 3   卡账号      61289 non-null  float64\n",
      " 4   类型名称     61289 non-null  object \n",
      " 5   操作金额(元)  61290 non-null  float64\n",
      " 6   余额(元)    61289 non-null  float64\n",
      " 7   消费类型     61289 non-null  object \n",
      " 8   餐厅       61289 non-null  object \n",
      " 9   餐别       61289 non-null  object \n",
      " 10  设备序列号    61289 non-null  float64\n",
      " 11  设备流水号    61289 non-null  float64\n",
      " 12  卡流水号     61289 non-null  float64\n",
      " 13  消费时间     61289 non-null  object \n",
      " 14  上传时间     61289 non-null  object \n",
      " 15  记录标志     61289 non-null  object \n",
      " 16  操作员      61289 non-null  float64\n",
      "dtypes: float64(8), object(9)\n",
      "memory usage: 7.9+ MB\n"
     ]
    }
   ],
   "source": [
    "# 获取表格各类信息\n",
    "df_dong.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>人员编号</th>\n",
       "      <th>部门名称</th>\n",
       "      <th>操作金额(元)</th>\n",
       "      <th>消费类型</th>\n",
       "      <th>餐别</th>\n",
       "      <th>消费时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>G13868</td>\n",
       "      <td>基础构架部</td>\n",
       "      <td>0.01</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>早餐</td>\n",
       "      <td>2020-07-04 02:39:44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>G13868</td>\n",
       "      <td>基础构架部</td>\n",
       "      <td>0.01</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>早餐</td>\n",
       "      <td>2020-07-04 02:56:27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>G13567</td>\n",
       "      <td>NBT Capital</td>\n",
       "      <td>18.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:49:32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>G9096</td>\n",
       "      <td>内容业务研发部</td>\n",
       "      <td>18.00</td>\n",
       "      <td>定值模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:49:49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>G11886</td>\n",
       "      <td>业务拓展研发部</td>\n",
       "      <td>20.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:50:05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61285</th>\n",
       "      <td>G13346</td>\n",
       "      <td>社会责任与公共关系发展中心</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:24:03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61286</th>\n",
       "      <td>G2885</td>\n",
       "      <td>营收研发部</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:28:52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61287</th>\n",
       "      <td>G13113</td>\n",
       "      <td>Noizz项目组</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:32:46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61288</th>\n",
       "      <td>G2543</td>\n",
       "      <td>电商项目组</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:41:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61289</th>\n",
       "      <td>汇总</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1155432.82</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>61290 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         人员编号           部门名称     操作金额(元)  消费类型   餐别                 消费时间\n",
       "0      G13868          基础构架部        0.01  金额模式   早餐  2020-07-04 02:39:44\n",
       "1      G13868          基础构架部        0.01  金额模式   早餐  2020-07-04 02:56:27\n",
       "2      G13567    NBT Capital       18.00  金额模式   中餐  2020-07-06 11:49:32\n",
       "3       G9096        内容业务研发部       18.00  定值模式   中餐  2020-07-06 11:49:49\n",
       "4      G11886        业务拓展研发部       20.00  金额模式   中餐  2020-07-06 11:50:05\n",
       "...       ...            ...         ...   ...  ...                  ...\n",
       "61285  G13346  社会责任与公共关系发展中心       16.00  金额模式   晚餐  2021-06-29 19:24:03\n",
       "61286   G2885          营收研发部       16.00  金额模式   晚餐  2021-06-29 19:28:52\n",
       "61287  G13113       Noizz项目组       16.00  金额模式   晚餐  2021-06-29 19:32:46\n",
       "61288   G2543          电商项目组       16.00  金额模式   晚餐  2021-06-29 19:41:00\n",
       "61289      汇总            NaN  1155432.82   NaN  NaN                  NaN\n",
       "\n",
       "[61290 rows x 6 columns]"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#删除不要的列\n",
    "df_dong.drop(['卡号',\n",
    "              '卡账号',\n",
    "              '余额(元)',\n",
    "              '操作员',\n",
    "              '设备序列号',\n",
    "              '设备流水号',\n",
    "              '卡流水号',\n",
    "              '上传时间',\n",
    "              '类型名称',\n",
    "              '餐厅',\n",
    "              '记录标志'],axis=1,inplace=True)\n",
    "df_dong"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>人员编号</th>\n",
       "      <th>部门名称</th>\n",
       "      <th>操作金额(元)</th>\n",
       "      <th>消费类型</th>\n",
       "      <th>餐别</th>\n",
       "      <th>消费时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>G13868</td>\n",
       "      <td>基础构架部</td>\n",
       "      <td>0.01</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>早餐</td>\n",
       "      <td>2020-07-04 02:39:44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>G13868</td>\n",
       "      <td>基础构架部</td>\n",
       "      <td>0.01</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>早餐</td>\n",
       "      <td>2020-07-04 02:56:27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>G13567</td>\n",
       "      <td>NBT Capital</td>\n",
       "      <td>18.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:49:32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>G9096</td>\n",
       "      <td>内容业务研发部</td>\n",
       "      <td>18.00</td>\n",
       "      <td>定值模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:49:49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>G11886</td>\n",
       "      <td>业务拓展研发部</td>\n",
       "      <td>20.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:50:05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61284</th>\n",
       "      <td>G8600</td>\n",
       "      <td>直播社交业务部</td>\n",
       "      <td>26.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:17:18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61285</th>\n",
       "      <td>G13346</td>\n",
       "      <td>社会责任与公共关系发展中心</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:24:03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61286</th>\n",
       "      <td>G2885</td>\n",
       "      <td>营收研发部</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:28:52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61287</th>\n",
       "      <td>G13113</td>\n",
       "      <td>Noizz项目组</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:32:46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61288</th>\n",
       "      <td>G2543</td>\n",
       "      <td>电商项目组</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:41:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>61289 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         人员编号           部门名称  操作金额(元)  消费类型  餐别                 消费时间\n",
       "0      G13868          基础构架部     0.01  金额模式  早餐  2020-07-04 02:39:44\n",
       "1      G13868          基础构架部     0.01  金额模式  早餐  2020-07-04 02:56:27\n",
       "2      G13567    NBT Capital    18.00  金额模式  中餐  2020-07-06 11:49:32\n",
       "3       G9096        内容业务研发部    18.00  定值模式  中餐  2020-07-06 11:49:49\n",
       "4      G11886        业务拓展研发部    20.00  金额模式  中餐  2020-07-06 11:50:05\n",
       "...       ...            ...      ...   ...  ..                  ...\n",
       "61284   G8600        直播社交业务部    26.00  金额模式  晚餐  2021-06-29 19:17:18\n",
       "61285  G13346  社会责任与公共关系发展中心    16.00  金额模式  晚餐  2021-06-29 19:24:03\n",
       "61286   G2885          营收研发部    16.00  金额模式  晚餐  2021-06-29 19:28:52\n",
       "61287  G13113       Noizz项目组    16.00  金额模式  晚餐  2021-06-29 19:32:46\n",
       "61288   G2543          电商项目组    16.00  金额模式  晚餐  2021-06-29 19:41:00\n",
       "\n",
       "[61289 rows x 6 columns]"
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#删除不要的行（最后一行）\n",
    "\n",
    "df_dong.drop([len(df_dong)-1],inplace=True)\n",
    "df_dong"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>人员编号</th>\n",
       "      <th>部门名称</th>\n",
       "      <th>操作金额(元)</th>\n",
       "      <th>消费类型</th>\n",
       "      <th>餐别</th>\n",
       "      <th>消费时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>G13567</td>\n",
       "      <td>NBT Capital</td>\n",
       "      <td>18.0</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:49:32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>G9096</td>\n",
       "      <td>内容业务研发部</td>\n",
       "      <td>18.0</td>\n",
       "      <td>定值模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:49:49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>G11886</td>\n",
       "      <td>业务拓展研发部</td>\n",
       "      <td>20.0</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:50:05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>G3736</td>\n",
       "      <td>营收研发部</td>\n",
       "      <td>20.0</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:50:09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>G5006</td>\n",
       "      <td>营收研发部</td>\n",
       "      <td>18.0</td>\n",
       "      <td>定值模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:50:37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61284</th>\n",
       "      <td>G8600</td>\n",
       "      <td>直播社交业务部</td>\n",
       "      <td>26.0</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:17:18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61285</th>\n",
       "      <td>G13346</td>\n",
       "      <td>社会责任与公共关系发展中心</td>\n",
       "      <td>16.0</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:24:03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61286</th>\n",
       "      <td>G2885</td>\n",
       "      <td>营收研发部</td>\n",
       "      <td>16.0</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:28:52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61287</th>\n",
       "      <td>G13113</td>\n",
       "      <td>Noizz项目组</td>\n",
       "      <td>16.0</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:32:46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61288</th>\n",
       "      <td>G2543</td>\n",
       "      <td>电商项目组</td>\n",
       "      <td>16.0</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:41:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>61287 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         人员编号           部门名称  操作金额(元)  消费类型  餐别                 消费时间\n",
       "2      G13567    NBT Capital     18.0  金额模式  中餐  2020-07-06 11:49:32\n",
       "3       G9096        内容业务研发部     18.0  定值模式  中餐  2020-07-06 11:49:49\n",
       "4      G11886        业务拓展研发部     20.0  金额模式  中餐  2020-07-06 11:50:05\n",
       "5       G3736          营收研发部     20.0  金额模式  中餐  2020-07-06 11:50:09\n",
       "6       G5006          营收研发部     18.0  定值模式  中餐  2020-07-06 11:50:37\n",
       "...       ...            ...      ...   ...  ..                  ...\n",
       "61284   G8600        直播社交业务部     26.0  金额模式  晚餐  2021-06-29 19:17:18\n",
       "61285  G13346  社会责任与公共关系发展中心     16.0  金额模式  晚餐  2021-06-29 19:24:03\n",
       "61286   G2885          营收研发部     16.0  金额模式  晚餐  2021-06-29 19:28:52\n",
       "61287  G13113       Noizz项目组     16.0  金额模式  晚餐  2021-06-29 19:32:46\n",
       "61288   G2543          电商项目组     16.0  金额模式  晚餐  2021-06-29 19:41:00\n",
       "\n",
       "[61287 rows x 6 columns]"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#删除测试操作的消费金额\n",
    "\n",
    "df_dong.drop([0,1],inplace=True)\n",
    "df_dong"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>人员编号</th>\n",
       "      <th>部门名称</th>\n",
       "      <th>操作金额(元)</th>\n",
       "      <th>消费类型</th>\n",
       "      <th>餐别</th>\n",
       "      <th>消费时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>G13868</td>\n",
       "      <td>基础构架部</td>\n",
       "      <td>0.01</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>早餐</td>\n",
       "      <td>2020-07-04 02:39:44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>G13868</td>\n",
       "      <td>基础构架部</td>\n",
       "      <td>0.01</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>早餐</td>\n",
       "      <td>2020-07-04 02:56:27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>G13567</td>\n",
       "      <td>NBT Capital</td>\n",
       "      <td>18.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:49:32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>G9096</td>\n",
       "      <td>内容业务研发部</td>\n",
       "      <td>18.00</td>\n",
       "      <td>定值模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:49:49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>G11886</td>\n",
       "      <td>业务拓展研发部</td>\n",
       "      <td>20.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>中餐</td>\n",
       "      <td>2020-07-06 11:50:05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61284</th>\n",
       "      <td>G8600</td>\n",
       "      <td>直播社交业务部</td>\n",
       "      <td>26.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:17:18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61285</th>\n",
       "      <td>G13346</td>\n",
       "      <td>社会责任与公共关系发展中心</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:24:03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61286</th>\n",
       "      <td>G2885</td>\n",
       "      <td>营收研发部</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:28:52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61287</th>\n",
       "      <td>G13113</td>\n",
       "      <td>Noizz项目组</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:32:46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61288</th>\n",
       "      <td>G2543</td>\n",
       "      <td>电商项目组</td>\n",
       "      <td>16.00</td>\n",
       "      <td>金额模式</td>\n",
       "      <td>晚餐</td>\n",
       "      <td>2021-06-29 19:41:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>61289 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         人员编号           部门名称  操作金额(元)  消费类型  餐别                 消费时间\n",
       "0      G13868          基础构架部     0.01  金额模式  早餐  2020-07-04 02:39:44\n",
       "1      G13868          基础构架部     0.01  金额模式  早餐  2020-07-04 02:56:27\n",
       "2      G13567    NBT Capital    18.00  金额模式  中餐  2020-07-06 11:49:32\n",
       "3       G9096        内容业务研发部    18.00  定值模式  中餐  2020-07-06 11:49:49\n",
       "4      G11886        业务拓展研发部    20.00  金额模式  中餐  2020-07-06 11:50:05\n",
       "...       ...            ...      ...   ...  ..                  ...\n",
       "61284   G8600        直播社交业务部    26.00  金额模式  晚餐  2021-06-29 19:17:18\n",
       "61285  G13346  社会责任与公共关系发展中心    16.00  金额模式  晚餐  2021-06-29 19:24:03\n",
       "61286   G2885          营收研发部    16.00  金额模式  晚餐  2021-06-29 19:28:52\n",
       "61287  G13113       Noizz项目组    16.00  金额模式  晚餐  2021-06-29 19:32:46\n",
       "61288   G2543          电商项目组    16.00  金额模式  晚餐  2021-06-29 19:41:00\n",
       "\n",
       "[61289 rows x 6 columns]"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#创建副本\n",
    "\n",
    "df = df_dong\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>操作金额(元)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>部门名称</th>\n",
       "      <th>人员编号</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>业务拓展研发部</th>\n",
       "      <th>G11886</th>\n",
       "      <td>2571.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">数据运营技术部</th>\n",
       "      <th>G3765</th>\n",
       "      <td>2396.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G12111</th>\n",
       "      <td>2382.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>业务中台技术中心</th>\n",
       "      <th>G13574</th>\n",
       "      <td>2149.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>欢聚-法务中心</th>\n",
       "      <th>G10132</th>\n",
       "      <td>2121.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OASIS产品部</th>\n",
       "      <th>JZ7050</th>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>欢聚-诚伯信息有限（不发餐补）</th>\n",
       "      <th>PQ0025</th>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>欢聚-卓越物业管理公司（不发餐补）</th>\n",
       "      <th>84491</th>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>质量与项目管理部</th>\n",
       "      <th>JZ6684</th>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rosetta</th>\n",
       "      <th>JZ7014</th>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5275 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                          操作金额(元)\n",
       "部门名称              人员编号           \n",
       "业务拓展研发部           G11886   2571.0\n",
       "数据运营技术部           G3765    2396.0\n",
       "                  G12111   2382.0\n",
       "业务中台技术中心          G13574   2149.0\n",
       "欢聚-法务中心           G10132   2121.0\n",
       "...                           ...\n",
       "OASIS产品部          JZ7050      1.0\n",
       "欢聚-诚伯信息有限（不发餐补）   PQ0025      1.0\n",
       "欢聚-卓越物业管理公司（不发餐补） 84491       1.0\n",
       "质量与项目管理部          JZ6684      1.0\n",
       "Rosetta           JZ7014      1.0\n",
       "\n",
       "[5275 rows x 1 columns]"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算每个员工的消费总额，并且按照消费总额由大到小排序\n",
    "df_ppl = df.groupby(['部门名称','人员编号']).sum().sort_values(by='操作金额(元)',ascending=False)\n",
    "df_ppl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>操作金额(元)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>部门名称</th>\n",
       "      <th>人员编号</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>业务拓展研发部</th>\n",
       "      <th>G11886</th>\n",
       "      <td>2571.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">数据运营技术部</th>\n",
       "      <th>G3765</th>\n",
       "      <td>2396.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G12111</th>\n",
       "      <td>2382.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>业务中台技术中心</th>\n",
       "      <th>G13574</th>\n",
       "      <td>2149.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>欢聚-法务中心</th>\n",
       "      <th>G10132</th>\n",
       "      <td>2121.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>总办</th>\n",
       "      <th>G9505</th>\n",
       "      <td>2002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>业务事业部</th>\n",
       "      <th>G7724</th>\n",
       "      <td>1952.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>欢聚-东木形至广州设计有限公司（不发餐补）</th>\n",
       "      <th>83942</th>\n",
       "      <td>1940.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>营收研发部</th>\n",
       "      <th>G11134</th>\n",
       "      <td>1862.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>基础构架部</th>\n",
       "      <th>G9708</th>\n",
       "      <td>1794.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              操作金额(元)\n",
       "部门名称                  人员编号           \n",
       "业务拓展研发部               G11886   2571.0\n",
       "数据运营技术部               G3765    2396.0\n",
       "                      G12111   2382.0\n",
       "业务中台技术中心              G13574   2149.0\n",
       "欢聚-法务中心               G10132   2121.0\n",
       "总办                    G9505    2002.0\n",
       "业务事业部                 G7724    1952.0\n",
       "欢聚-东木形至广州设计有限公司（不发餐补） 83942    1940.0\n",
       "营收研发部                 G11134   1862.0\n",
       "基础构架部                 G9708    1794.0"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 可以找出一年来支持该店家最多的员工，在周年庆活动的时候联系行政继续定向优惠，进而进行营销活动\n",
    "\n",
    "df_ppl.iloc[0:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>操作金额(元)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>部门名称</th>\n",
       "      <th>人员编号</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">AI技术部</th>\n",
       "      <th>G10149</th>\n",
       "      <td>667.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G10165</th>\n",
       "      <td>98.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G11293</th>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G11698</th>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G11814</th>\n",
       "      <td>78.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">金融部</th>\n",
       "      <th>G5480</th>\n",
       "      <td>420.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G9066</th>\n",
       "      <td>77.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G9865</th>\n",
       "      <td>196.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>JZ5902</th>\n",
       "      <td>271.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>非标业务中心</th>\n",
       "      <th>JZ6442</th>\n",
       "      <td>53.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5275 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               操作金额(元)\n",
       "部门名称   人员编号           \n",
       "AI技术部  G10149    667.0\n",
       "       G10165     98.0\n",
       "       G11293     20.0\n",
       "       G11698     20.0\n",
       "       G11814     78.0\n",
       "...                ...\n",
       "金融部    G5480     420.0\n",
       "       G9066      77.0\n",
       "       G9865     196.0\n",
       "       JZ5902    271.0\n",
       "非标业务中心 JZ6442     53.0\n",
       "\n",
       "[5275 rows x 1 columns]"
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照部门分组，并且计算每个人的消费总额\n",
    "df_department = df.groupby(['部门名称','人员编号']).sum()\n",
    "df_department"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>操作金额(元)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>部门名称</th>\n",
       "      <th>人员编号</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">AI技术部</th>\n",
       "      <th>G12110</th>\n",
       "      <td>702.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G10149</th>\n",
       "      <td>667.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G11931</th>\n",
       "      <td>656.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G9614</th>\n",
       "      <td>649.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G9752</th>\n",
       "      <td>437.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">金融部</th>\n",
       "      <th>G9865</th>\n",
       "      <td>196.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G12307</th>\n",
       "      <td>140.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G4862</th>\n",
       "      <td>87.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G9066</th>\n",
       "      <td>77.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>非标业务中心</th>\n",
       "      <th>JZ6442</th>\n",
       "      <td>53.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5275 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               操作金额(元)\n",
       "部门名称   人员编号           \n",
       "AI技术部  G12110    702.0\n",
       "       G10149    667.0\n",
       "       G11931    656.0\n",
       "       G9614     649.0\n",
       "       G9752     437.5\n",
       "...                ...\n",
       "金融部    G9865     196.0\n",
       "       G12307    140.0\n",
       "       G4862      87.0\n",
       "       G9066      77.0\n",
       "非标业务中心 JZ6442     53.0\n",
       "\n",
       "[5275 rows x 1 columns]"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 以每个部门为单位，按照部门内消费总额排序，顺序是从大到小\n",
    "df_department = df_department.groupby(level='部门名称',group_keys=False).apply(lambda x:x.sort_values(by='操作金额(元)',ascending=False))\n",
    "df_department"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AI技术部最大消费金额的人员为：G12110\n",
      "BCM Social Corp最大消费金额的人员为：G13536\n",
      "Biugo项目组最大消费金额的人员为：G11092\n",
      "COO办公室最大消费金额的人员为：G13059\n",
      "CSR中心最大消费金额的人员为：JZ5411\n",
      "CTO办公室最大消费金额的人员为：G12964\n",
      "E项目技术中心最大消费金额的人员为：G12552\n",
      "GBO最大消费金额的人员为：G16103\n",
      "Hago业务研发部最大消费金额的人员为：G13956\n",
      "LIVE 营收部最大消费金额的人员为：G9704\n",
      "NBT Capital最大消费金额的人员为：G13567\n",
      "Noizz项目组最大消费金额的人员为：G13876\n",
      "OASIS产品部最大消费金额的人员为：G14104\n",
      "RESEARCH LAB最大消费金额的人员为：G8701\n",
      "RTC技术部最大消费金额的人员为：G15228\n",
      "Rosetta最大消费金额的人员为：G15949\n",
      "SAAS研发中心最大消费金额的人员为：G15710\n",
      "UED中心最大消费金额的人员为：G7095\n",
      "VIP（不发餐补）最大消费金额的人员为：VIP612\n",
      "V项目最大消费金额的人员为：G16585\n",
      "一件业务中心最大消费金额的人员为：JZ6243\n",
      "业务中台技术中心最大消费金额的人员为：G13574\n",
      "业务事业部最大消费金额的人员为：G7724\n",
      "业务拓展中心最大消费金额的人员为：G14135\n",
      "业务拓展研发部最大消费金额的人员为：G11886\n",
      "业务研发部最大消费金额的人员为：G5585\n",
      "互娱平台技术部最大消费金额的人员为：G16175\n",
      "产品一部最大消费金额的人员为：G12129\n",
      "产品二部最大消费金额的人员为：G10579\n",
      "企业管理线最大消费金额的人员为：G5888\n",
      "全球化市场部最大消费金额的人员为：G9456\n",
      "公共与政府事务部最大消费金额的人员为：JZ5720\n",
      "内容业务研发部最大消费金额的人员为：G9079\n",
      "内容安全中心最大消费金额的人员为：G12020\n",
      "内容安全中心（不发餐补）最大消费金额的人员为：G12851\n",
      "内容拓展部最大消费金额的人员为：G9710\n",
      "内容部最大消费金额的人员为：G10006\n",
      "北京分公司（不发餐补）最大消费金额的人员为：B1303\n",
      "后端技术部最大消费金额的人员为：G7418\n",
      "基建项目组最大消费金额的人员为：G0246\n",
      "基础构架部最大消费金额的人员为：G9708\n",
      "大吉大利项目组最大消费金额的人员为：G1402\n",
      "客户端技术部最大消费金额的人员为：G5745\n",
      "客服中心最大消费金额的人员为：G6663\n",
      "市场部最大消费金额的人员为：G10118\n",
      "平台部最大消费金额的人员为：G7777\n",
      "广告业务中心最大消费金额的人员为：G16204\n",
      "广州津虹最大消费金额的人员为：JZ6921\n",
      "总办最大消费金额的人员为：G9505\n",
      "战略部最大消费金额的人员为：G12244\n",
      "技术研发部最大消费金额的人员为：G3944\n",
      "投资者关系部最大消费金额的人员为：G15729\n",
      "推荐算法技术部最大消费金额的人员为：G5029\n",
      "支付业务中心最大消费金额的人员为：G16045\n",
      "支付中心最大消费金额的人员为：JZ6187\n",
      "政策发展部最大消费金额的人员为：G9673\n",
      "数据产品中心最大消费金额的人员为：G17077\n",
      "数据运营技术部最大消费金额的人员为：G3765\n",
      "新工具项目组最大消费金额的人员为：G11172\n",
      "欢聚-东木形至广州设计有限公司（不发餐补）最大消费金额的人员为：83942\n",
      "欢聚-人力资源部最大消费金额的人员为：G13288\n",
      "欢聚-人瑞（不发餐补）最大消费金额的人员为：83881\n",
      "欢聚-信必优（深圳）不发餐补最大消费金额的人员为：84363\n",
      "欢聚-内审中心最大消费金额的人员为：G13013\n",
      "欢聚-卓越物业管理公司（不发餐补）最大消费金额的人员为：81891\n",
      "欢聚-博彦（不发餐补）最大消费金额的人员为：84309\n",
      "欢聚-外包-君阳保洁公司（不发餐补）最大消费金额的人员为：88974\n",
      "欢聚-广州Shopline（不发餐补）最大消费金额的人员为：84139\n",
      "欢聚-广州春晖园林有限公司（不发餐补）最大消费金额的人员为：81468\n",
      "欢聚-德科信息（不发餐补）最大消费金额的人员为：84490\n",
      "欢聚-法务中心最大消费金额的人员为：G10132\n",
      "欢聚-行政中心最大消费金额的人员为：G14608\n",
      "欢聚-诚伯信息有限（不发餐补）最大消费金额的人员为：PQ0014\n",
      "欢聚-财务部最大消费金额的人员为：G12553\n",
      "欢聚上海分公司（不发餐补）最大消费金额的人员为：G16089\n",
      "欢聚云事业部最大消费金额的人员为：G4261\n",
      "欢聚传媒最大消费金额的人员为：G0598\n",
      "欢聚集团最大消费金额的人员为：B1760\n",
      "比邻项目组最大消费金额的人员为：G9789\n",
      "津虹-AI技术部最大消费金额的人员为：G8913\n",
      "津虹-RTC技术部最大消费金额的人员为：G9708\n",
      "津虹-SAAS研发中心最大消费金额的人员为：G2891\n",
      "津虹-UED最大消费金额的人员为：G3737\n",
      "津虹-YDC设计中心最大消费金额的人员为：G16566\n",
      "津虹-业务中台技术中心最大消费金额的人员为：G1516\n",
      "津虹-业务事业部最大消费金额的人员为：G12674\n",
      "津虹-互动直播部最大消费金额的人员为：G16250\n",
      "津虹-产品中心最大消费金额的人员为：G16265\n",
      "津虹-人力资源部最大消费金额的人员为：G10354\n",
      "津虹-人瑞（不发餐补）最大消费金额的人员为：83393\n",
      "津虹-公共与政府事务部最大消费金额的人员为：G9676\n",
      "津虹-公共实务中心最大消费金额的人员为：G16516\n",
      "津虹-内审中心最大消费金额的人员为：G3303\n",
      "津虹-内容安全中心最大消费金额的人员为：G1366\n",
      "津虹-内容部最大消费金额的人员为：JZ6544\n",
      "津虹-卓越物业管理公司（不发餐补）最大消费金额的人员为：84340\n",
      "津虹-君阳保洁公司（不发餐补）最大消费金额的人员为：83947\n",
      "津虹-娱乐营收中心最大消费金额的人员为：G16370\n",
      "津虹-客服中心最大消费金额的人员为：G6663\n",
      "津虹-市场中心最大消费金额的人员为：G16763\n",
      "津虹-总办最大消费金额的人员为：G4600\n",
      "津虹-技术线最大消费金额的人员为：G14788\n",
      "津虹-推荐算法中心最大消费金额的人员为：G7509\n",
      "津虹-支付业务中心最大消费金额的人员为：G14641\n",
      "津虹-数据中心最大消费金额的人员为：JZ6726\n",
      "津虹-法务部最大消费金额的人员为：G10631\n",
      "津虹-渠道运营中心最大消费金额的人员为：G16567\n",
      "津虹-游戏直播中心最大消费金额的人员为：SX6959\n",
      "津虹-生态运营中心最大消费金额的人员为：JZ6763\n",
      "津虹-电商业务研发部最大消费金额的人员为：G8002\n",
      "津虹-研发部最大消费金额的人员为：G2081\n",
      "津虹-社交工具产品中心最大消费金额的人员为：G12506\n",
      "津虹-行政中心最大消费金额的人员为：G4488\n",
      "津虹-诚伯信息有限（不发餐补）最大消费金额的人员为：84237\n",
      "津虹-财务部最大消费金额的人员为：JZ6713\n",
      "津虹-质量与项目管理部最大消费金额的人员为：G9495\n",
      "津虹-资源采购中心最大消费金额的人员为：G8429\n",
      "流量运营部最大消费金额的人员为：G5384\n",
      "海外业务增长中心最大消费金额的人员为：G14356\n",
      "海外用户增长中心最大消费金额的人员为：G14804\n",
      "深圳shopline（不发餐补）最大消费金额的人员为：G16528\n",
      "游戏部最大消费金额的人员为：G4997\n",
      "电商业务研发部最大消费金额的人员为：G14547\n",
      "电商产品部最大消费金额的人员为：G14109\n",
      "电商项目组最大消费金额的人员为：G11381\n",
      "直播社交业务部最大消费金额的人员为：G8600\n",
      "直播社交研发部最大消费金额的人员为：G8815\n",
      "直播部最大消费金额的人员为：G7409\n",
      "研发效能部最大消费金额的人员为：G15384\n",
      "研发管理部最大消费金额的人员为：G9715\n",
      "研发部最大消费金额的人员为：G15298\n",
      "社交工具产品中心最大消费金额的人员为：G13803\n",
      "社交工具技术中心最大消费金额的人员为：G14551\n",
      "社会责任与公共关系发展中心最大消费金额的人员为：G12957\n",
      "移动语音业务研发部最大消费金额的人员为：G0184\n",
      "自营电商中心最大消费金额的人员为：JZ6592\n",
      "营收增值部最大消费金额的人员为：G10094\n",
      "营收技术部最大消费金额的人员为：G6977\n",
      "营收研发部最大消费金额的人员为：G11134\n",
      "语音产品技术中心最大消费金额的人员为：G15581\n",
      "语音产品部最大消费金额的人员为：G15209\n",
      "财经投资并购及管理部最大消费金额的人员为：G14606\n",
      "质量与研发管理部最大消费金额的人员为：G12500\n",
      "质量与项目研发部最大消费金额的人员为：G16237\n",
      "质量与项目管理部最大消费金额的人员为：G9772\n",
      "资源中心最大消费金额的人员为：G6638\n",
      "资源管理部（不发餐补）最大消费金额的人员为：G13551\n",
      "资源采购中心最大消费金额的人员为：JZ6235\n",
      "跨境业务中心最大消费金额的人员为：G16194\n",
      "运维部最大消费金额的人员为：G7396\n",
      "运营部最大消费金额的人员为：G6723\n",
      "采购中心最大消费金额的人员为：G1804\n",
      "金融部最大消费金额的人员为：G10566\n",
      "非标业务中心最大消费金额的人员为：JZ6442\n"
     ]
    }
   ],
   "source": [
    "# 获得每个部门一年中累计消费最多的那个人，可以对此推送感谢优惠\n",
    "for name,df_name in df_department.groupby(\"部门名称\"):\n",
    "    list_test = {}\n",
    "    #把不同部门形分类成成一个组 \n",
    "    for index,row in df_name.iterrows():\n",
    "        list_test[index]=row['操作金额(元)']   \n",
    "    list_test=sorted(list_test.items(),key=lambda x:x[1],reverse=True) \n",
    "    print(name + '最大消费金额的人员为：'+ str(list_test[0][0][-1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>操作金额(元)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>部门名称</th>\n",
       "      <th>人员编号</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">AI技术部</th>\n",
       "      <th>G10149</th>\n",
       "      <td>19.617647</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G10165</th>\n",
       "      <td>19.600000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G11293</th>\n",
       "      <td>20.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G11698</th>\n",
       "      <td>20.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G11814</th>\n",
       "      <td>19.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">金融部</th>\n",
       "      <th>G5480</th>\n",
       "      <td>19.090909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G9066</th>\n",
       "      <td>19.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G9865</th>\n",
       "      <td>19.600000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>JZ5902</th>\n",
       "      <td>18.066667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>非标业务中心</th>\n",
       "      <th>JZ6442</th>\n",
       "      <td>17.666667</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5275 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 操作金额(元)\n",
       "部门名称   人员编号             \n",
       "AI技术部  G10149  19.617647\n",
       "       G10165  19.600000\n",
       "       G11293  20.000000\n",
       "       G11698  20.000000\n",
       "       G11814  19.500000\n",
       "...                  ...\n",
       "金融部    G5480   19.090909\n",
       "       G9066   19.250000\n",
       "       G9865   19.600000\n",
       "       JZ5902  18.066667\n",
       "非标业务中心 JZ6442  17.666667\n",
       "\n",
       "[5275 rows x 1 columns]"
      ]
     },
     "execution_count": 169,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照部门分组，并且计算每个人的消费总额的平均值\n",
    "df_average = df.groupby(['部门名称','人员编号']).mean()\n",
    "df_average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "每个人的消费总额的平均值的中位数是： 操作金额(元)    18.25\n",
      "dtype: float64\n",
      "每个人的消费总额的平均值的众数是：    操作金额(元)\n",
      "0     16.0\n"
     ]
    }
   ],
   "source": [
    "# 每个人的消费总额的平均值的中位数\n",
    "print('每个人的消费总额的平均值的中位数是：',df_average.median())\n",
    "\n",
    "# 每个人的消费总额的平均值的众数\n",
    "print('每个人的消费总额的平均值的众数是：',df_average.mode())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "所有人的平均消费价格是： 18.85220545285451\n",
      "所有人消费价格的中位数是： 18.0\n",
      "所有人消费价格的众数是： 0    18.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 所有人的平均消费价格\n",
    "print('所有人的平均消费价格是：',df['操作金额(元)'].mean())\n",
    "\n",
    "# 所有人消费价格的中位数\n",
    "print('所有人消费价格的中位数是：',df['操作金额(元)'].median())\n",
    "\n",
    "# 所有人消费价格的众数\n",
    "print('所有人消费价格的众数是：',df['操作金额(元)'].mode())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, '月消费金额总量')"
      ]
     },
     "execution_count": 168,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 26376 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 20221 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 28040 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 36153 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 37329 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 39069 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 24635 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 37327 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 26376 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 20221 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 28040 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 36153 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 37329 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 39069 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 24635 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/Users/emmalui/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 37327 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAEiCAYAAADEasRGAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3de5hcVZnv8e+PBLmICSE0CLnYIFEHGD2QGCJ6HDQK8XIMahiDw5DRePLIoOJllAQ9ovJkhOMFBxE8GQmBiEJE58AoFyPIoHNCMCBMBEQygBCJJJiI8UIg4T1/rFVDdVvddKf2qqpUfp/nqaer3n159+qqrrfXXqt2KSIwMzOr2i7tPgAzM+tOLjBmZlaEC4yZmRXhAmNmZkW4wJiZWREj230AnWLfffeN3t7edh+GmdkO5bbbbnssInoaLXOByXp7e1m1alW7D8PMbIci6ZcDLfMpMjMzK8IFxszMinCBMTOzIlxgzMysCBcYMzMroliBkbRY0npJP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QRN3VBnm5qi/N0bg7n6dwcTfEpsgIk7RIRT3dDnm5qi/N0bg7n6dwczXCBMTOzIjyLzMzMinCBMTOzIlxgzMysCBcYMzMrwgXGzMyK8OdgzDqIpE8B04Da19+OBG5pFIuIT7X6+MyGwwXGrPPMjojfAkjaG/jgADGzjuZTZGZmVoQLjJmZFeECY2ZmRbjAmJlZES4wZmZWhAuMmZkV4WnKZp1lPXCppNol2Hchff96o5hZR/Pl+s3MrAifIjMzsyJcYMzMrAgXGDMzK8IFxszMivj/M/NeX3yGJfMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 求每个月的营业额，并画出柱状图，可以得知店家在含节假日的月份营收能力较差，并且容易受到疫情的冲击\n",
    "\n",
    "import math\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.rcParams['font.sans-serif']=['SimHei']\n",
    "df['消费时间'] = pd.to_datetime(df['消费时间'], format=\"%Y-%m-%d %H:%M:%S\", errors='coerce')\n",
    "\n",
    "# 对原数据进行复制 避免后续操作对原数据产生影响\n",
    "new_df =df.copy()\n",
    "\n",
    "# 添加month列，将消费时间换算为年月（如202006）\n",
    "new_df['month'] = new_df['消费时间'].map(lambda x: 100*x.year + x.month)\n",
    "\n",
    "# 把month列换成字符串类型，避免后期对坐标轴产生影响\n",
    "new_df['month'] = new_df['month'].map(lambda x:str(x))\n",
    "\n",
    "# 对新增的month列进行聚合，统计该累加后的分布\n",
    "month_count = new_df.groupby('month')['操作金额(元)'].sum()\n",
    "\n",
    "# keys()表示用groupby后的索引就是月份，y就是把操作金额形成列表\n",
    "x=month_count.keys()\n",
    "y = list(month_count)\n",
    "plt.bar(x,y)\n",
    "\n",
    "# 调整x轴的旋转度\n",
    "plt.xticks(rotation=60)\n",
    "plt.xlabel('月份')\n",
    "plt.ylabel('月消费金额总量')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
